package mianshi.java;

import org.junit.Test;
import org.junit.platform.commons.util.StringUtils;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.*;

@RunWith(JUnit4.class)
public class Main {
    public static void main(String[] args) {
        String exp = "1 + 2 * (9 - 5)";
        SuffixExpression se = compile(exp);
        int result = se.execute();
        System.out.println(exp + " = " + result + " " + (result == 1 + 2 * (9 - 5) ? "✓" : "✗"));
    }

    static SuffixExpression compile(String exp) {
        if (StringUtils.isBlank(exp)){
            return null;
        }
        // TODO:
        Stack<Object> stack = new Stack<>();
        for (int i = exp.length(); i > 0; i--) {


        }
        return new SuffixExpression(stack);
    }
}


class SuffixExpression {
    private Stack stack;

    public SuffixExpression(Stack stack){
        this.stack = stack;
    }
    int execute() {
        // TODO:
        return 0;
    }
}

interface Collection {

    default void a(){
        System.out.println(Thread.currentThread().getName());
    }
}

class ArrayList implements Collection{

    public static void main(String[] args) {
        new Collection(){}.a();
    }
}


class binarySearchTest{
    private static int binarySearch0(int[] a, int fromIndex, int toIndex,
                                     int key) {
        int low = fromIndex;
        int high = toIndex - 1;

        while (low <= high) {
            int mid = (low + high) >>> 1;
            int midVal = a[mid];

            if (midVal < key)
                low = mid + 1;
            else if (midVal > key)
                high = mid - 1;
            else
                return mid; // key found
        }
        return -(low + 1);  // key not found.
    }

    public static void main(String[] args) {
        int[] a = {1,2,3,4,5,6,98,7,76768,1};
        int index = binarySearch0(a, 0, a.length, 7);
        System.out.println(index);
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
    }
}


